﻿
define(function (require, exports) {
    $(function () {
        $("#btnRestore").click(function () {
            var val = $("#infoList option:selected").text().split('|')[0];
            if ($("#infoList option:selected").val() == '-99') {
                $.messager.alert('提示', '请选择备份点!');
                return;
            }
            $.messager.confirm('提示', '确定要还原备份点<br/>' + val + '?<br/>同时清空当月同步到本地的申请数据', function (r) {
                if (r) {
                    $.ajax({
                        url: "../BackRestore/RestoreRemoteData",
                        data: { backTime: val },
                        dataType: "json",
                        success: function (result) {
                            if (result.Result) {
                                $.messager.alert('提示', result.Message);
                            } else {
                                $.messager.alert('提示', result.Exception);

                            }
                        }
                    });
                }
            });
        });

        $("#btnBackUp").click(function () {
            $.ajax({
                url: "../BackRestore/BackRemoteData",
                data: {},
                dataType: "json",
                success: function (result) {
                    if (result) {
                        $.messager.alert('提示', '备份成功');
                    } else {
                        $.messager.alert('提示', '备份失败');

                    }
                }
            });
        });

        $("#btnAutoSign").click(function () {
            var btn = $(this).find(".l-btn-text");
            var btnValue = btn.html();
            $.ajax({
                url: "../BackRestore/AutoSign",
                data: {},
                dataType: "json",
                beforeSend: function () {
                    btn.html("处理ing...请等待");
                    btn.attr("disabled", "disabled");
                },
                type: "post",
                success: function (result) {
                    if (result.Result) {
                        $.messager.alert('提示', result.Message);
                    } else {
                        $.messager.alert('提示', result.Exception);

                    }
                },
                complete: function () {
                    btn.html(btnValue);
                    btn.removeAttr("disabled");
                }
            });
        });

        var loadBackUpList = function () {
            $.ajax({
                url: "../BackRestore/GetBackUpInfoList",
                dataType: "json",
                success: function (result) {
                    $.each(result, function (index, item) {
                        var option = $("<option data=" + item.BackUpTime + ">" + item.BackUpTime + "|" + item.Counts + "条</option>");
                        $("#infoList").append(option);
                    });
                }
            });
        }

        loadBackUpList(); //加载下拉框


    });
});